//全局混合
export default {
  methods: {
    gotoRoute(url,p) {
      // 路由跳转
      this.p = p || 1
      this.$router.push({ path: url ,
        query:{
          redirect:this.$route.path
      } });
    },
    getPhoneCode(mobile) {//获取手机验证码
      return new Promise((resolve, reject) => {
        this.$http
          .get("/nb-web/api/system/code/phone", {
            params:{
              mobile,
            }
          })
          .then(res => {
            if (res.data.code == "001") {
              resolve(res)
            }else{
              this.$swal(res.data.msg,{
                icon:'/static/img/tan_chuang.png'
              })
            }
          });
      });
    },
    getemailCode(accountt) {//获取邮箱验证码
      return new Promise((resolve, reject) => {
        this.$http
          .get("/nb-web/api/system/code/email", {
            params:{
              account:accountt
            }
          })
          .then(res => {
            if (res.data.code == "001") {
              resolve(res)
            }else{
              this.$swal(res.data.msg,{
                icon:'/static/img/tan_chuang.png'
              })
            }
          });
      });
    },
    
    countdown(){ // 倒计时
      // 组件data 必须参数
      // phone: null,
      // ifDisabled: false,
      // btnText: this.$t('r_hqyzm'),
      // timer: null,
      let time = 120;
      this.ifDisabled = true;
      this.timer = setInterval(()=>{
          time--;
          this.btnText = `${time}s`;
          if (time <= 0) {
              this.ifDisabled = false;
              this.btnText = this.$t('u_hq');
              clearInterval(this.timer);
          }
      },1000)
    },
    getPublicKey() {
      //获取 加密 key
      return new Promise((resolve, reject) => {
        this.$http.get("/nb-web/api/system/pubkey", {}).then(res => {
          if (res.data.code == "001") {
            resolve(res.data.result.data); //在 then 回调中处理结果
          }
        });
      });
    },
    exists(){ // 验证用户是否绑定手机号
      this.$http.post('/nb-web/api/user/phone/exists',{
        account:this.$cookie.getCookie('account').replace(/\"/g, "")
      }).then(res=>{
        if (res.data.code != '001') {
          this.$swal(this.$t('u_qxbdsj'),{
            icon:'/static/img/tan_chuang.png'
          }).then(val=>{
            this.gotoRoute('/user/account/bind_phone');
          })
        }
      })
   },
   email(){//验证用户是否绑定邮箱

   }
  },
  created(){

  },
  destroyed(){
    clearInterval(this.timer);
  }
};
